{- Cost.inc.orc -- Orc program Cost.inc
 - 
 - $Id$
 - 
 - Created by akattepu on 07-Aug-2012 17:06:40
 -}

def bestQoS(comparer, publisher) = head(sortBy(comparer, publisher))
val curTime = Rclock()
def CostValue() = [Random(10),Random(10),Random(10)]

type Items = Number
def Items() = signal
type CurrencyEuros = Number
def CurrencyEuros(y) = y*100 
type CurrencyDollars = Number
def CurrencyDollars(y) = y*80 

-- Types and Definitions for Cost
type Cost = Number
def class Cost(unit) =
  def QoS(String,List[Number]) :: List[Number]
  def UnitConverter(X,unit) = Ift(unit=Items) >> X | Ift(unit=CurrencyEuros) >> map(CurrencyEuros,X) | Ift(unit=CurrencyDollars) >> map(CurrencyDollars,X)
  def QoS(sitex,c)=
  val s = Ref([])
  signal >> (s? >q> (Ift(q=[]) >> s:=c >> s? | Iff(q=[]) >> QoSOplus(s?,c)  >v> s:=v >> UnitConverter(s?,unit) ))
--s? >x> QoSOplus(x,c) >q> s:= q >> s?

  def QoSOplus(List[Number],List[Number]) :: List[Number]
  def QoSOplus(c1,c2) =
    def Oplus([],[]) = []
    def Oplus(x:xs,y:ys) = (x+y):Oplus(xs,ys)
    Oplus(c1,c2)
  
  def QoSCompare(List[Number],List[Number]) :: List[Number]
  def QoSCompare(c1,c2) =
    def Compare([],[]) = true
    def Compare(x:xs,y:ys) = (x <= y) && Compare(xs,ys)
    Compare(c1,c2)

  def QoSCompete(List[Number],List[Number]) :: List[Number]
  def QoSCompete(c1,c2) = bestQoS(QoSCompare,[c1,c2])
  
  def QoSVee(List[Number],List[Number]) :: List[Number]
  def QoSVee(c1,c2) =
    def Vee([],[]) = []
    def Vee(x:xs,y:ys) = max(x,y):Vee(xs,ys)
    Vee(c1,c2)
  stop